<?php 
header("Vary: Accept-Encoding");
header("Content-Type: application/javascript");
header("Transfer-Encoding: gzip");
header("Expires: Thu, 27 Mar 2012 08:52:00 GMT");
?>
var logged = false;
var root = "http://www.inrich.it/rclasse";
function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}
var md5_script = "/rclasse/js/md5-min.js";
include_dom(md5_script);

function show_news(id){
	var url = root+"/recupera_news.php";
	req = new Ajax.Request(url,
			  {
			    	method:'post',
			    	parameters: {id: id},
			    	onSuccess: function(transport){
			      		var response = transport.responseText || "no response text";
			      		if(response == "ko"){
			      			alert("Impossibile completare l'operazione richiesta. Riprovare tra qualche secondo o segnalare l'errore al webmaster");
				     		return;
			     		}
			     		else{
			     			var dati = response.split("|");
			     			var win = new Window({className: "mac_os_x",  width:400, height:null, zIndex: 100, resizable: true, title: "Leggi news", showEffect:Effect.Appear, hideEffect: Effect.Fade, draggable:true, wiredDrag: true});
			            	win.getContent().update("<div style='font-weight: bold; font-size: 12px; text-align: center; margin-top: 20px' class='Titolo'>"+dati[0]+"</div><div style='text-align: center; font-weight: normal; font-size: 11px; padding: 10px; margin-top: 20px; padding-bottom: 35px'>"+dati[1]+"</div>");     
			            	win.showCenter(true);
			     		}
			    	},
			    	onFailure: function(){ alert("Si e' verificato un errore..."); }
			  });
}

/*
 * funzione di login unica
 */


function coming_soon(){
    alert('Coming soon');
}

function trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}


function register(){
    coming_soon();
}

function do_logout(){
    document.location.href = "/logout.php";
}

function in_array(ar, val){
    //alert("==="+val+"===");
    for(var i = 0; i < ar.length; i++)
        if(ar[i] == val)
            return true;

    return false;
}

function genera_password(nome, cognome){
	//alert("Ricevo "+nome+" e "+cognome);
	ar_nome = nome.split("");
	nm_rev = ar_nome.reverse();
	ar_cognome = cognome.split("");
	cg_rev = ar_cognome.reverse();
	var pwd = nm_rev[0]+nm_rev[1]+nm_rev[2]+nm_rev[3];
	pwd += (Math.random()*100).toString().substr(0,2);
	pwd += cg_rev[0]+cg_rev[1]+nm_rev[0]+nm_rev[1];
	pass = pwd.toLowerCase();
	alert("La nuova password e': "+pass);
	return hex_md5(pass);
}

window.open_centered = function(url, name, width, height, options){
	var leftS = (screen.width - width) / 2;
	var topS = (screen.height - height) / 2;
	var pop = this.open(url, name, 'width='+width+', height='+height+', left='+leftS+', top='+topS);
	return pop;
};

window._alert = function(string){
	openInfoDialog(string, 3);
};

function valida_data(strData){
	var strLen = strData.length;
    var newData = "";
    if(strLen != 10)
    	return false;
    var reg_exp = /\d\d\/\d\d\/\d\d\d\d/;
    if(!strData.match(reg_exp))
    	return false;
    if (strLen > 0){
    	for (var ic=0;ic<=strLen;ic++){
        	if (strData.charAt(ic) != " ")
            	newData = newData + strData.charAt(ic);
        }
        // alert(newData);
    }
    else{
        return (false);
    }

    //divido la stringa in 3 pezzi
    if (newData.length > 0){
    	var arData = newData.split(/[^\d]/);
        if (arData.length != 3)
        	return(false);
    }
    else{
    	return (false);
    }

    giorno = parseInt(arData[0]);
    mese = parseInt(arData[1]);
    anno = parseInt(arData[2]);
    var trueFlag = true;

    if ((arData[2] > 2200)||(arData[2] < 1800))//>
    	trueFlag = false;

    if ((arData[1] > 12)||(arData[1] < 1))//>
        trueFlag = false;

    if ((arData[0] > 31)||(arData[0] < 1))//>
        trueFlag = false;
    if ((arData[1] == 4 || arData[1] == 6 || arData[1] == 9 || arData[1] == 11) && arData[0] == 31)
        trueFlag = false;
    if (arData[1] == 2){
        var isleap=(arData[2]%4==0 && (arData[2]%100!=0 || arData[2]%400==0));
        if (arData[0] > 29 || (arData[0] == 29 && !isleap))
    	    trueFlag = false;
    }
    return(trueFlag);
}

var timeout;
var exec_code;
function openInfoDialog(msg, tm) {
	var html = "<div style='width: 100%, text-align: center; font-size: 12px; font-weight: bold; padding-top: 30px; margin: auto'>"+msg+"</div>";
	Dialog.info(html, 
	{
		width:250, 
		height:100, 
		showProgress: false,
		className: "alphacube"
	}); 
	timeout = tm; 
	setTimeout(infoTimeout, 1000);
} 
function infoTimeout() { 
	timeout--; 
	if (timeout > 0) { 
		//Dialog.setInfoMessage(messages[index]); 
		setTimeout(infoTimeout, 1000); 
	} 
	else{
		Dialog.closeInfo();
	}
}
